package com.xu.service;


import com.xu.mapper.UserCourseMapper;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Map;

@Component
@RabbitListener(queues = "DirectQueue")
public class DirectReceiver {

    @Autowired
    private UserCourseMapper userCourseMapper;

    @RabbitHandler
    public void process(Map<String,Object> message) {
        //System.out.println("DirectReceiver消费者收到消息  : " + message.toString());
        String method = (String)message.get("method");
        int userId = Integer.valueOf((String) message.get("userId"));
        int courseId = Integer.valueOf((String) message.get("courseId"));
        if (method.equals("add")){
            userCourseMapper.addUserCourse(userId,courseId);
        }
        if (method.equals("delete")){
            userCourseMapper.delUserCourse(userId,courseId);
        }



    }

}
